﻿<!DOCTYPE html>
<!--课件试题选项编辑-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

    <style>
        .el-form-item__content {
            margin: 0 !important;
        }
    </style>

</head>

<body>


    <div id="app" v-cloak class="popupW100">

        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
            size="mini">
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item prop="optionName">
                            <el-input type="text" v-model="Form.optionName" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{Coursewaremanagement.OptionName+mark.m}}
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.optionName" slot="suffix"
                                           :placeholder="Coursewaremanagement.OptionName">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option label="A" value="A"></el-option>
                                    <el-option label="B" value="B"></el-option>
                                    <el-option label="C" value="C"></el-option>
                                    <el-option label="D" value="D"></el-option>
                                </el-select>
                            </el-input>
                            <span class="iputLineMust" v-if="Form.optionName<=0 || Form.optionName==undefined">
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item  prop="optionComment">
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{Coursewaremanagement.OptionComment+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea" v-model="Form.optionComment"
                                          autocomplete="off">
                                </el-input>
                                <span class="iputLineMust" v-if="Form.optionComment<=0 || Form.optionComment==undefined">
                                    <img src="/static/images/exclamation.png" alt="">
                                </span>
                            </div>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row>
                <!--<el-col :sqpn="24">
                    <p class="el-form-item__label">{{Coursewaremanagement.IsAnswer+mark.m}}</p>
                    <br>
                    <el-form-item prop="IsConsumables">
                        <el-radio-group v-model="Form.IsAnswer">
                            <el-radio v-for="item in IsAnswer" :label="item.value" :value="item.key">{{item.value}}
                            </el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>-->


                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item prop="isAnswer">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{Coursewaremanagement.IsAnswer+mark.m}}
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.isAnswer" slot="suffix"
                                           :placeholder="Coursewaremanagement.IsAnswer" autocomplete="off">
                                    <el-option v-for="item in IsAnswerL" :label="item.value"
                                               :value="item.value"></el-option>
                                </el-select>
                            </el-input>
                            <span class="iputLineMust" v-if="Form.isAnswer<=0 || Form.isAnswer==undefined">
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>

            </el-row>


            <el-row type="flex" justify="end">
                <el-form-item>
                    <!--<el-button type="primary" @click="onSubmitForm">{{col.btnCommit}}</el-button>-->
                    <el-button type="primary" @click="onSubmitForm('ruleForm')" :loading="ListItem.loadingbut">{{col.btnCommit}}</el-button>
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
    </div>
    <script type="text/javascript">
        var app = new Vue({
            el: '#app',
            data: {
                //父业传参
                ListItem: ListItem,
                id: '',
                //业务表单内容
                Form: {
                    optionName: '',
                    optionComment: '',//内容
                    isAnswer: '',
                },
                IsAnswerL: [],
                //表单验证
                rules: {
                    optionName: [
                        verification.NotNull
                    ],
                    optionComment: [
                        verification.NotNull
                    ],
                    isAnswer: [
                        verification.NotNull
                    ],
                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //提交数据
                test: function () { },
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            //判断是否选择题型
                            mythis.ListItem.loadingbut = true;

                          
                            var b = false;
                            var a = false;
                            var num = 0;
                            for (var i = 0; i < parent.app.Form.zB_QuestionsOptions.length; i++) {
                               
                                //console.log('parent.app.Form.zB_QuestionsOptions[i].option', parent.app.Form.zB_QuestionsOptions[i].option);
                                //console.log('mythis.Form.optionComment', mythis.Form.optionComment);
                                //console.log('mythis.Form.isAnswer', mythis.Form.isAnswer);

                                if (parent.app.Form.zB_QuestionsOptions[i].option == mythis.Form.optionName) {
                                    b = true;

                                }
                                if (parent.app.Form.zB_QuestionsOptions[i].content == mythis.Form.optionComment) {
                                    a = true;
                                }

                                

                            }
                            //debugger;
                            mythis.ListItem.loadingbut = false;
                            if (a) {
                                showMessage('请勿添加重复的内容选项！', 'error');
                                return false;

                            }

                            if (b) {

                                showMessage('请勿添加重复选项！', 'error');
                                return false;

                            }

                            //alert('bbbbbb');

                            var option = mythis.Form.optionName;
                            var content = mythis.Form.optionComment;

                            parent.app.Form.zB_QuestionsOptions.push({
                                option: option,
                                content: content,
                                isAnswer: mythis.Form.isAnswer
                            });

                            parent.app.ListItem.dialogVisible = false;
                        } else {
                            //验证失败
                            return false;
                        }
                    });



                }
                //onSubmitForm: function () {
                //    var OptionName = this.Form.OptionName;
                //    var OptionComment = this.Form.OptionComment;

                //    parent.app.Form.OptionsList.push({
                //        OptionName: OptionName,
                //        OptionComment: OptionComment,
                //        IsAnswer: this.Form.IsAnswer
                //    });
                //    parent.app.ListItem.dialogVisible = false;
                //}
            },
            mounted: function () {
                this.IsAnswerL = getDicData('zbkjglanswer');//总部_课件管理_是否是正确答案 1 是、0 否
            },
        });
    </script>
</body>

</html>